#ifndef REPORT_H
#define REPORT_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <shmem.h>
#include <math.h>
#include <log_utils.h>
#include "cJSON.h"
#include "MQTTClient.h"
#include <unix_sock.h>

#define DATAM0 6
#define DATAMODBUS 5

struct reprot
{
    int type;
    int period;
};
struct mqtt_server
{
    char *addr;
    int port;
};
struct mb_dev
{
    char *addr;
    int port;
};
struct data_m0
{
    int key;
    char *name;
    int type;
};
struct m0
{
    char *name;
    struct data_m0 dam0[6];
};
struct data_modbus
{
    int key;
    char *name;
    int addr;
    int type;
};
struct modbus
{
    char *name;
    struct data_modbus damo[5];
};

typedef struct total_cjson
{
    char *version;
    struct reprot rep;
    struct mqtt_server mqse;
    struct mb_dev mbde;
    struct m0 m;
    struct modbus mod;
} t_cjson;

union val_t
{
    int b_val;   // bool类型存储空间
    int i_val;   //整形值存储空间
    float f_val; //浮点值存储空间
};

struct std_node
{
    int key;             //唯一键值
    int type;            //数据点值的类型，1：bool类型 2：int型  3：float型
    int dev_type;        //属于哪个设备：m0或modbus 0为m0、1为modbus
    union val_t old_val; //变化上报后需要更新旧值
    union val_t new_val; //从共享内存取出最新数据，放到new_val中
    int ret;             //默认为-1，采集成功后设置为0，采集失败再置-1
};

#endif